#include<bits/stdc++.h>
using namespace std;
using ll=long long;
ll n,m;
char s[50005],t[1005];
ll kmp[1005];
ll aut[1005][27];
ll f[50005][1005];
int main(){
	freopen("neck.in","r",stdin);
	freopen("neck.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	cin>>(s+1)>>(t+1);
	n=strlen(s+1),m=strlen(t+1);
	for(int i=2;i<=m;i++) {
		ll j=i-1;
		while(1) {
			if(t[kmp[j]+1]==t[i]) {
				kmp[i]=kmp[j]+1;
				break;
			}
			if(!j)	
				break;
			j=kmp[j];
		}
	}
	for(int i=0;i<m;i++) 
		for(int j=0;j<26;j++)
			if(t[i+1]-'a'==j)
				aut[i][j]=i+1;
			else 
				aut[i][j]=aut[kmp[i]][j];
	for(int i=0;i<=n;i++)
		for(int j=0;j<=m;j++)
			f[i][j]=INT_MAX;
	f[0][0]=0;
	for(int i=0;i<n;i++) 
		for(int j=0;j<m;j++) {
			f[i+1][aut[j][s[i+1]-'a']]=min(f[i+1][aut[j][s[i+1]-'a']],f[i][j]);
			f[i+1][j]=min(f[i+1][j],f[i][j]+1);
		}
	ll ans=INT_MAX;
	for(int i=0;i<m;i++)
		ans=min(ans,f[n][i]);
	cout<<n-ans;
	return 0;
}



